home *** CD-ROM | disk | FTP | other *** search
- extern double MACHEP, MAXNUM;
-
- /* Factorials of integers from 0 through 33 */
- double fac[] = {
- 1.0,
- 1.0,
- 2.0,
- 6.0,
- 2.4E1,
- 1.2E2,
- 7.2E2,
- 5.04E3,
- 4.032E4,
- 3.6288E5,
- 3.6288E6,
- 3.99168E7,
- 4.790016E8,
- 6.2270208E9,
- 8.71782912E10,
- 1.307674368E12,
- 2.0922789888E13,
- 3.55687428096E14,
- 6.402373705728E15,
- 1.21645100408832E17,
- 2.43290200817664E18,
- 5.109094217170944E19,
- 1.12400072777760768E21,
- 2.585201673888497664E22,
- 6.2044840173323943936E23,
- 1.5511210043330985984E25,
- 4.03291461126605635584E26,
- 1.0888869450418352160768E28,
- 3.04888344611713860501504E29,
- 8.841761993739701954543616E30,
- 2.6525285981219105863630848E32,
- 8.22283865417792281772556288E33,
- 2.6313083693369353016721801216E35,
- 8.68331761881188649551819440128E36
- };
-
-
- /* ellpe.c
- *
- * Complete elliptic integral of the second kind
- *
- *
- *
- * SYNOPSIS:
- *
- * double m1, y, ellpe();
- *
- * y = ellpe( m1 );
- *
- *
- *
- * DESCRIPTION:
- *
- * Approximates the integral
- *
- *
- * pi/2
- * -
- * | | 2
- * E(m) = | sqrt( 1 - m sin t ) dt
- * | |
- * -
- * 0
- *
- * Where m = 1 - m1, using the approximation
- *
- * P(x) - x log x Q(x).
- *
- * Though there are no singularities, the argument m1 is used
- * rather than m for compatibility with ellpk().
- *
- * E(1) = 1; E(0) = pi/2.
- *
- *
- * ACCURACY:
- *
- * Relative error:
- * arithmetic domain # trials peak rms
- * DEC 0, 1 13000 3.1e-17 9.4e-18
- * IEEE 0, 1 10000 2.1e-16 7.3e-17
- *
- *
- * ERROR MESSAGES:
- *
- * message condition value returned
- * ellpe domain x<0, x>1 0.0
- *
- */
-
- /*
- Cephes Math Library, Release 2.1: February, 1989
- Copyright 1984, 1987, 1989 by Stephen L. Moshier
- Direct inquiries to 30 Frost Street, Cambridge, MA 02140
- */
-
- static double PE[] = {
- 1.53552577301013293365E-4,
- 2.50888492163602060990E-3,
- 8.68786816565889628429E-3,
- 1.07350949056076193403E-2,
- 7.77395492516787092951E-3,
- 7.58395289413514708519E-3,
- 1.15688436810574127319E-2,
- 2.18317996015557253103E-2,
- 5.68051945617860553470E-2,
- 4.43147180560990850618E-1,
- 1.00000000000000000299E0
- };
- static double QE[] = {
- 3.27954898576485872656E-5,
- 1.00962792679356715133E-3,
- 6.50609489976927491433E-3,
- 1.68862163993311317300E-2,
- 2.61769742454493659583E-2,
- 3.34833904888224918614E-2,
- 4.27180926518931511717E-2,
- 5.85936634471101055642E-2,
- 9.37499997197644278445E-2,
- 2.49999999999888314361E-1
- };
-
- double ellpe(x)
- double x;
- {
- double polevl(), log();
-
-
- if( (x <= 0.0) || (x > 1.0) )
- {
- if( x == 0.0 )
- return( 1.0 );
- printf( "ellpe domain error\n" );
- return( 0.0 );
- }
-
- return( polevl(x,PE,10) - log(x) * (x * polevl(x,QE,9)) );
- }
-
- /* ellpk.c
- *
- * Complete elliptic integral of the first kind
- *
- *
- *
- * SYNOPSIS:
- *
- * double m1, y, ellpk();
- *
- * y = ellpk( m1 );
- *
- *
- *
- * DESCRIPTION:
- *
- * Approximates the integral
- *
- *
- *
- * pi/2
- * -
- * | |
- * | dt
- * K(m) = | ------------------
- * | 2
- * | | sqrt( 1 - m sin t )
- * -
- * 0
- *
- * where m = 1 - m1, using the approximation
- *
- * P(x) - log x Q(x).
- *
- * The argument m1 is used rather than m so that the logarithmic
- * singularity at m = 1 will be shifted to the origin; this
- * preserves maximum accuracy.
- *
- * K(0) = pi/2.
- *
- * ACCURACY:
- *
- * Relative error:
- * arithmetic domain # trials peak rms
- * DEC 0,1 16000 3.5e-17 1.1e-17
- * IEEE 0,1 30000 2.5e-16 6.8e-17
- *
- * ERROR MESSAGES:
- *
- * message condition value returned
- * ellpk domain x<0, x>1 0.0
- *
- */
-
-
- /*
- Cephes Math Library, Release 2.0: April, 1987
- Copyright 1984, 1987 by Stephen L. Moshier
- Direct inquiries to 30 Frost Street, Cambridge, MA 02140
- */
-
- static double PK[] =
- {
- 1.37982864606273237150E-4,
- 2.28025724005875567385E-3,
- 7.97404013220415179367E-3,
- 9.85821379021226008714E-3,
- 6.87489687449949877925E-3,
- 6.18901033637687613229E-3,
- 8.79078273952743772254E-3,
- 1.49380448916805252718E-2,
- 3.08851465246711995998E-2,
- 9.65735902811690126535E-2,
- 1.38629436111989062502E0
- };
-
- static double QK[] =
- {
- 2.94078955048598507511E-5,
- 9.14184723865917226571E-4,
- 5.94058303753167793257E-3,
- 1.54850516649762399335E-2,
- 2.39089602715924892727E-2,
- 3.01204715227604046988E-2,
- 3.73774314173823228969E-2,
- 4.88280347570998239232E-2,
- 7.03124996963957469739E-2,
- 1.24999999999870820058E-1,
- 4.99999999999999999821E-1
- };
- static double C1 = 1.3862943611198906188E0; /* log(4) */
-
-
-
- double ellpk(x)
- double x;
- {
- double polevl(), log();
-
-
-
- if( (x < 0.0) || (x > 1.0) )
- {
- printf( "ellpk domain error\n" );
- return( 0.0 );
- }
-
- if( x > MACHEP )
- {
- return( polevl(x,PK,10) - log(x) * polevl(x,QK,10) );
- }
- else
- {
- if( x == 0.0 )
- {
- printf( "ellpk singularity\n" );
- return( MAXNUM );
- }
- else
- {
- return( C1 - 0.5 * log(x) );
- }
- }
- }
-
-
- /* polevl.c
- * p1evl.c
- *
- * Evaluate polynomial
- *
- *
- *
- * SYNOPSIS:
- *
- * int N;
- * double x, y, coef[N+1], polevl[];
- *
- * y = polevl( x, coef, N );
- *
- *
- *
- * DESCRIPTION:
- *
- * Evaluates polynomial of degree N:
- *
- * 2 N
- * y = C + C x + C x +...+ C x
- * 0 1 2 N
- *
- * Coefficients are stored in reverse order:
- *
- * coef[0] = C , ..., coef[N] = C .
- * N 0
- *
- * The function p1evl() assumes that coef[N] = 1.0 and is
- * omitted from the array. Its calling arguments are
- * otherwise the same as polevl().
- *
- *
- * SPEED:
- *
- * In the interest of speed, there are no checks for out
- * of bounds arithmetic. This routine is used by most of
- * the functions in the library. Depending on available
- * equipment features, the user may wish to rewrite the
- * program in microcode or assembly language.
- *
- */
-
-
- /*
- Cephes Math Library Release 2.1: December, 1988
- Copyright 1984, 1987, 1988 by Stephen L. Moshier
- Direct inquiries to 30 Frost Street, Cambridge, MA 02140
- */
-
-
- double polevl( x, coef, N )
- double x;
- double coef[];
- int N;
- {
- double ans;
- int i;
- double *p;
-
- p = coef;
- ans = *p++;
- i = N;
-
- do
- ans = ans * x + *p++;
- while( --i );
-
- return( ans );
- }
-
- /* p1evl() */
- /* N
- * Evaluate polynomial when coefficient of x is 1.0.
- * Otherwise same as polevl.
- */
-
- double p1evl( x, coef, N )
- double x;
- double coef[];
- int N;
- {
- double ans;
- double *p;
- int i;
-
- p = coef;
- ans = x + *p++;
- i = N-1;
-
- do
- ans = ans * x + *p++;
- while( --i );
-
- return( ans );
- }
-